<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8" />
  <title>06_组件</title>
  <!-- 引入Vue -->
  <script type="text/javascript" src="../js/vue.js"></script>
</head>

<body>
  <!-- 准备好一个容器-->
  <div id="demo">
    <!-- <h2>人员信息</h2>
    <h3>姓名:{{PresonName}}</h3>
    <h3>年龄:{{PresonAge}}</h3>
    <button @click="showPerson">提示个人信息</button>
    <hr>
    <h2>学校信息</h2>
    <h3>校名:{{SchoolName}}</h3>
    <h3>地址:{{SchoolAddress}}</h3>
    <button @click="showSchool">提示学校信息</button> -->
  </div>
</body>

<script type="text/javascript">
  //阻止 vue 在启动时生成生产提示。
  Vue.config.productionTip = false;


  /*
    创建组件时:
    1. 

  */
  // 创建Person实例
  let Person = Vue.extend({
    template: `
        <div>
              <h2>人员信息</h2>
               <h3>姓名:{{PresonName}}</h3>
               <h3>年龄:{{PresonAge}}</h3>
               <button @click="showPerson">提示个人信息</button>
      </div>`,
    data() {
      return {
        PresonName: '程程',
        PresonAge: '18',
      }
    },
    methods: {
      showPerson() {
        alert(`我叫${this.PresonName},今年${this.PresonAge}岁了`)
      },
    },
  })
  // 创建School组件
  let School = Vue.extend({
    template: `
            <div>
              <h2>学校信息</h2>
               <h3>校名:{{SchoolName}}</h3>
               <h3>地址:{{SchoolAddress}}</h3>
               <button @click="showSchool">提示学校信息</button>
            </div>`,
    data() {
      return {
        SchoolAddress: '宏福科技园',
        SchoolName: '尚硅谷',
      }
    },
    methods: {
      showSchool() {
        alert(`${this.SchoolName}坐落于${this.SchoolAddress}`)
      }
    },
  })

  // 创建app组件
  let App = Vue.extend({
    components: { Person, School },
    template: `
        <div>
          <Person></Person>
          <School></School>
        </div>` ,
  })

  // 创建vm
  new Vue({
    el: '#demo',
    components: { App },
    template: `<App></App>`
  })
</script>

</html>